<?php
require_once "../../mainfile.php";

$sql_desc = sprintf("select * from %s order by poll_id",
			   $xoopsDB->prefix('xoopspoll_desc'));
			   
$ret_desc = $xoopsDB->query($sql_desc);
while ($re_desc = $xoopsDB->fetchArray($ret_desc)){
	$insert_desc = sprintf("insert into %s select poll_id,question,description,user_id,start_time,end_time,votes,voters,multiple,display,weight,mail_status,0,0 from %s where poll_id=%d",
						   $xoopsDB->prefix('opinion_desc'), 
						   $xoopsDB->prefix('xoopspoll_desc'),
						   $re_desc['poll_id']);
//	echo $insert_desc.";\n";
	var_dump($xoopsDB->queryF($insert_desc));
	$sql_option = sprintf("select * from %s where poll_id=%d order by option_id ",
						  $xoopsDB->prefix('xoopspoll_option'),
						  $re_desc['poll_id']);
//	echo $sql_option.";\n";
	$ret_option = $xoopsDB->query($sql_option);
	$option_num = 0;
	while ($re_option = $xoopsDB->fetchArray($ret_option)){
		$option_num++;
		$insert_option = sprintf("insert into %s (poll_id, option_num, option_text, option_count, option_color) values (%d, %d, '%s', %d, '%s')",
								 $xoopsDB->prefix('opinion_option'),
								 $re_option['poll_id'],
								 $option_num,
								 $re_option['option_text'],
								 $re_option['option_count'],
								 $re_option['option_color']
								 );
//		echo $insert_option.";\n";
		var_dump($xoopsDB->queryF($insert_option));
		$sql_log = sprintf("select * from %s where poll_id=%d and option_id=%d",
						   $xoopsDB->prefix('xoopspoll_log'),
						   $re_option['poll_id'],
						   $re_option['option_id']);
		
		$ret_log = $xoopsDB->query($sql_log);
		while ($re_log = $xoopsDB->fetchArray($ret_log)){
			$insert_log = sprintf("insert into %s (poll_id, option_id, ip, user_id, `time`) values(%d, %d, '%s', %d, %d)",
								  $xoopsDB->prefix('opinion_log'),
								  $re_log['poll_id'],
								  $option_num,
								  $re_log['ip'],
								  $re_log['user_id'],
								  $re_log['time']);
//			echo $insert_log.";\n"; 
			var_dump($xoopsDB->queryF($insert_log));
		}
	}
}

